/**
 * Main application module
 */
var app = {
	// Modules to load
	_modules : [],
	// Stage container
	_stage : null,
	// Application panels
	_panels : null,
	_currentArea : null,
	_currentLocation : null,
	
	/**
	 * Application init
	 */
	init : function() {
		this._stage = $('#stage');
		this._panels = $('#panels');
		
		for (var i = 0; i < this._modules.length; i++) {
			var moduleName = this._modules[i];
			var module = this[moduleName];
			
			if (module && module.init) {
				var panelContent = module.init();
				var panel = $('#panel_' + moduleName);
				
				if (panelContent) {
					if (!panel.size()) {
						panel = $('<div>')
							.addClass('panel')
							.attr('id', 'panel_' + moduleName)
							.append(panelContent)
							.append($('<div>').addClass('clr'))
							.appendTo(this._panels);
					}
					else {
						panel.append(panelContent);
					}
				}
			}
		}
		
		this.show('area');
	},
	
	/**
	 * Add module to load query
	 *
	 * @param name Module name
	 */
	addModule : function(name) {
		this._modules.push(name);
	},
	
	/**
	 * Show module panel
	 *
	 * @param name Panel name
	 */
	show : function(name) {
		$('.panel', this._stage).appendTo(this._panels);
		$('#panel_' + name).appendTo(this._stage);
	}
};